﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TMIS.BLL
{
    public class Student
    {
        /// <summary>
        /// 根据学生姓名和学生密码判断学生信息是否存在
        /// </summary>
        /// <param name="name">学生姓名</param>
        /// <param name="password">学生密码</param>
        /// <returns></returns>
        public bool Check(string name, string password)
        {
            DAL.Student dal=DALFactory.DALFactory.CreateStudent();
            if(dal.Check(name,password)!=Guid.Empty)
            {
                return true;
            }
            else 
            {
                return false;
            }
        }
        /// <summary>
        /// 获取院系名称对应的ID号
        /// </summary>
        /// <param name="department"></param>
        /// <returns></returns>
        public Guid GetDepartmentID(string department)
        {
            DAL.Department dal = DALFactory.DALFactory.CreateDepartment();
            return dal.Search(department);
        }
        /// <summary>
        /// 获取所有院系名称
        /// </summary>
        /// <returns></returns>
        public string[] GetDepartment()
        {
            DAL.Department dal = DALFactory.DALFactory.CreateDepartment();
            return dal.Search();
        }

        /// <summary>
        /// 获取专业名称对应的ID号
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public Guid GetProfessionID(string profession)
        {
            DAL.Profession dal = DALFactory.DALFactory.CreateProfession();
            return dal.Search(profession);
        }
        /// <summary>
        /// 获取指定院系名称的专业名称
        /// </summary>
        /// <param name="department"></param>
        /// <returns></returns>
        public string[] GetProfession(string department)
        {
            DAL.Profession dal = DALFactory.DALFactory.CreateProfession();
            return dal.Search(this.GetDepartmentID(department));
        }

        /// <summary>
        /// 获取年级名称对应的ID号
        /// </summary>
        public Guid GetGradeID(string grade)
        {
            DAL.Grade dal = DALFactory.DALFactory.CreateGrade();
            return dal.Search(grade);
        }
        /// <summary>
        /// 获取指定专业名称的年级名称
        /// </summary>
        /// <param name="profession"></param>
        /// <returns></returns>
        public string[] GetGrade(string profession)
        {
            DAL.Grade dal = DALFactory.DALFactory.CreateGrade();
            return dal.Search(this.GetProfessionID(profession));
        }

        /// <summary>
        /// 获取班级名称对应的ID号
        /// </summary>
        public Guid GetClassID(string classes)
        {
            DAL.Classes dal = DALFactory.DALFactory.CreateClass();
            return dal.Search(classes);
        }
        /// <summary>
        /// 获取指定年级名称的班级名称
        /// </summary>
        /// <param name="classes"></param>
        /// <returns></returns>
        public string[] GetClass(string classes)
        {
            DAL.Classes dal = DALFactory.DALFactory.CreateClass();
            return dal.Search(this.GetGradeID(classes));
        }

        /// <summary>
        /// 获取教师名称对应的ID号
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public Guid GetTeacherID(string name)
        {
            DAL.Teacher dal = DALFactory.DALFactory.CreateTeacher();
            return dal.Search(name);
        }
        /// <summary>
        /// 获取所有教师名称
        /// </summary>
        /// <returns></returns>
        public string[] GetTheacher()
        {
            DAL.Teacher dal = DALFactory.DALFactory.CreateTeacher();
            return dal.GetName();
        }

        /// <summary>
        /// 获取论文名称对应的ID号
        /// </summary>
        /// <param name="thesis"></param>
        /// <returns></returns>
        public Guid GetThesisID(string thesis)
        {
            DAL.Thesis dal = DALFactory.DALFactory.CreateThesis();
            return dal.Search(thesis);
        }
        /// <summary>
        /// 获取所有论文名称
        /// </summary>
        /// <returns></returns>
        public string[] GetThesis()
        {
            DAL.Thesis dal = DALFactory.DALFactory.CreateThesis();
            return dal.Search();
        }

        public void Save(Model.Student stu)
        {
            DAL.Student sdal = DALFactory.DALFactory.CreateStudent();
            sdal.Add(stu);

            #region 为新用户初始化各表信息
            DAL.Approval adal = DALFactory.DALFactory.CreateApproval();
            adal.Insert(new Model.Approval { ID = stu.ID,BeginDate=DateTime.Now,CompleteDate=DateTime.Now });
            DAL.OpenReport odal = DALFactory.DALFactory.CreateOpenReport();
            odal.Insert(new Model.OpenReport { ID = stu.ID });
            DAL.InstructionOpinion idal = DALFactory.DALFactory.CreateInstructionOpinion();
            idal.Insert(new Model.InstructionOpinion { ID = stu.ID });
            DAL.ReviewOpinion rdal = DALFactory.DALFactory.CreateReviewOpinion();
            rdal.Insert(new Model.ReviewOpinion { ID = stu.ID });
            DAL.Reply redal = DALFactory.DALFactory.CreateReply();
            redal.Insert(new Model.Reply { ID = stu.ID });
            DAL.Identify iddal = DALFactory.DALFactory.CreateIdentify();
            iddal.Insert(new Model.Identify { ID = stu.ID,Date=DateTime.Now});
            DAL.Recommend reddal = DALFactory.DALFactory.CreateRecommend();
            reddal.Insert(new Model.Recommend { ID = stu.ID });
            #endregion

        }

    }
}
